package thread;

import sun.font.TextSource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-08-17
 * Time: 11:28
 */
/*
public class Demo9 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
           while(!Thread.currentThread().isInterrupted()) {
               System.out.println("Thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   System.out.println("线程 t 终止运行");
                   throw new RuntimeException(e);

                   //Thread.currentThread().setDaemon(true);
                   //break;
               }
           }
        });
        //t.setDaemon(true);
        t.start();
        Thread.sleep(3000);
        //把上述标志位设置为true
        t.interrupt();
    }
}
*/


public class Demo9 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
           //while (!Thread.currentThread().isInterrupted()) {
           while (Thread.interrupted()) {
               System.out.println("hello Thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   //e.printStackTrace();
                   break;
               }
           }
        });
        t.start();
        Thread.sleep(3000);

        t.interrupt();
    }
}
